import path from "path";
import fsExtra from "fs-extra";
const { existsSync, remove, copy } = fsExtra;
const cwd = process.cwd();
//打包发布路径，谨慎改动
const releaseRelativePath = "../server/public/kfkVABMHpPRG";
const distPath = path.resolve(cwd, "dist");
const releasePath = path.resolve(cwd, releaseRelativePath);

async function build() {
  if (existsSync(releasePath)) {
    await remove(releasePath);
  }
  try {
    await copyFile(distPath, releasePath);
  } catch (error) {}
}

function copyFile(sourceDir, targetDir) {
  return new Promise((resolve, reject) => {
    copy(sourceDir, targetDir, (err) => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}

build();
